<%
    var obj={pageTitle:"商品列表"}
%>
{{include "../layout_header.html"}}
<div class=" container-fluid">
    <div class=" page-header">
        <h2 class=" text-center text-primary">商品列表</h2>
    </div>
    <form class=" form-inline" style="margin: 10px 0" action="/goodsInfo/list" method="GET">
        <input type="hidden" name="pageIndex" value="1">
        <div class=" form-group">
            <label for="" class=" control-label">商品名称</label>
            <input type="text" name="goodsname" placeholder="输入商品名称" class=" form-control">
        </div>
        <div class=" form-group">
            <label for="" class=" control-label">商品分类</label>
            <select class="form-control" name="categoryid">
                <option value="">-请选择-</option>
                {{each categoryInfoList item index}}
                <option value="{{item.categoryid}}">{{item.categoryname}}</option>
                {{/each}}
            </select>
        </div>
        <div class=" form-group">
            <label for="" class=" control-label">商品价格</label>
            <input type="text" class="form-control" name="minprice" placeholder="最低价格">
            --
            <input type="text" class="form-control" name="maxprice" placeholder="最高价格">
        </div>
            
        <div class=" form-group">
            <!-- submit提交表单 -->
            <button type="submit" class=" btn btn-primary">
                <span class=" glyphicon glyphicon-search"></span>查询
            </button>
        </div>
    </form>

    <div class=" btn-group">
        <a href="/goodsInfo/addGoodsInfo" class=" btn btn-primary">
            <span class=" glyphicon glyphicon-plus"></span>新增
        </a>
        <button type="button" class=" btn btn-warning btn-edit">
            <span class=" glyphicon glyphicon-pencil"></span>编辑
        </button>
        <button type="button" class=" btn btn-danger btn-delete">
            <span class=" glyphicon glyphicon-trash"></span>删除
        </button>
        <button type="button" class=" btn btn-info" onclick="window.open('/goodsInfo/exportToExcel'+location.search)">
            <span class=" glyphicon glyphicon-export"></span>导出为EXCEL
        </button>
    </div>
    <div class=" table-responsive">
        <table class=" table table-hover table-striped table-bordered table-vertical-center">
            <tr>
                <th>
                    <label for="ckAll">
                        <input type="checkbox" id="ckAll" data-toggle="ckAll" data-target="[name='ck']">全选
                    </label>
                </th>
                <th>商品名称</th>
                <th>商品价格</th>
                <th>商品折扣</th>
                <th>商品总数</th>
                <th>商品状态</th>
                <th>商品分类</th>
                <th>商品图片</th>
                <th>操作</th>
            </tr>

            {{each goodsInfoList item index}}
            
            <tr>
                <td>
                    <input type="checkbox" name="ck" value="{{item.goodsid}}">
                </td>
                <td>{{item.goodsname}}</td>
                <td>{{item.goodsprice}}</td>
                <td>{{item.goodsoffset}}</td>
                <td>{{item.goodscount}}</td>
                <td>
                    <label class="label {{item.goodsstatus==1?'label-primary':'label-danger'}}">{{item.goodsstatus==1?"上架":"已下架"}}</label>
                </td>
                <td>{{item.categoryname}}</td>
                <td>
                    <img class="goodsimgpreview img-thumbnail" style="height: 40px;" src="{{item.goodsimg}}" alt="商品图片">
                </td>
                <td>
                    <a href="/goodsInfo/editGoodsInfo/{{item.goodsid}}" class="label label-warning">编辑</a>
                </td>
            </tr>
            {{/each}}
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $(".goodsimgpreview").click(function () {
            //先拿到当前图片的地址
            imgSrc = $(this).attr("src");
            //调用插件的方法
            layer.photos({
                photos: {
                    data: [{
                        src: imgSrc
                    }]
                }
                
            });
        });
        $(".btn-delete").click(function(){
            var cks=$("[name='ck']:checked");
            if(cks.length==0){
                layer.alert("请选择你要删除的元素");
            }
            else{
                var cksValue=[];
                cks.each(function(index,ele){
                    cksValue.push(ele.value);
                });
                $.get("/goodsInfo/deleteGoodsInfo",{
                    cksValue:JSON.stringify(cksValue)
                },function(data){
                    if(data==true){
                        layer.alert("删除成功",function(index){
                            layer.close(index);
                            location.reload();
                        })
                    }
                    else{
                        layer.alert("删除失败");
                    }
                })
            }
        })
    })
</script>
{{include "../layout_pagination.html"}}


